package com.box.service.redis.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.box.service.redis.service.JedisClient;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**   
*    
* 项目名称：MyBox   
* 类名称：JedisClientSingle   
* 类描述：   redis缓存实现类
* 创建人：君无邪   
* 创建时间：2019年11月20日 上午11:48:09   
* 修改备注：  https://www.java214.com 
* @version    1.0
*    
*/ 
@Service
public class JedisClientSingle implements JedisClient {
	
	//注入jedispool
	@Autowired
	private JedisPool jedisPool;
	
	public String Set(String key, String value) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		String result = jedis.set(key, value);
		 jedis.close();
		return result;
	}

	public String get(String key) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		String result = jedis .get(key);
		jedis.close();
		return result ;
	}

	public Long hset(String key, String item, String value) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		Long result=jedis.hset(key, item, value);
		jedis.close();
		return result;
	}

	public String hget(String key, String item) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		String result = jedis.hget(key, item);
		jedis.close();
		return result ;
	}

	public Long incr(String key) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		 Long result = jedis.incr(key);
			jedis.close();
		return result;
	}

	public Long decr(String key) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		 Long result   = jedis.decr(key);
			jedis.close();
		return result ;
	}

	public Long expire(String key, Integer second) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		 Long result = jedis.expire(key, second);
			jedis.close();
		return result ;
	}

	/* (non-Javadoc)
	 * @see com.taotao.rest.component.JedisClient#ttl(java.lang.String)
	 */
	public Long ttl(String key) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		 Long result = jedis.ttl(key);
		 jedis.close();
			return result ;
	}

	public Long hdel(String key, String item) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
	Long result=	jedis.hdel(key, item);
	 jedis.close();
		return result;
	}

	public Long del(String key) {
		// TODO Auto-generated method stub
		Jedis jedis = jedisPool.getResource();
		Long result=	jedis.del(key);
		 jedis.close();
			return result;
	}

}
